package eval.host;

import java.util.List;
import java.util.Map;

import eval.deploy.IDemandManager;
import eval.exceptions.CpuLeakAtHostException;
import eval.exceptions.MemLeakAtHostException;
import eval.vm.VirtualMachine;

/**
 * Interface for the main operations offered by the host manager
 * 
 * @author Nicolo' M. Calcavecchia <calcavecchia@elet.polimi.it>
 */
public interface IHostManager {

	/**
	 * Adds the given host to the list of known hosts by the host manager
	 * 
	 * */
	public void addHost(Host host);

	public void addHosts(List<Host> hosts);

	/**
	 * Returns the total number of hosts in the cloud infrastructure
	 * */
	public int getNumberOfHosts();

	/**
	 * Returns the list of all generated hosts
	 * */
	public List<Host> getHosts();

	/**
	 * Returns the cpu capacity for the given host number.
	 * 
	 * The host number starts from 0
	 * */
	public int getCpuCapacityForHost(Host host);

	/**
	 * Returns the mem capacity for the given host number.
	 * 
	 * The host number starts from 0
	 * */
	public int getMemCapacityForHost(Host host);

	/**
	 * Prints into the console all hosts in the system
	 * */
	public void printAllHosts();

	/**
	 * Returns the total CPU capacity of hosts available in the data center
	 * */
	public int getTotalCpuCapacity();

	/**
	 * Returns the total mem capacity of hosts available in the data center
	 * */
	public int getTotalMemCapacity();

	/**
	 * Returns a Map associating at each king of host the percentage of that
	 * type of hosts
	 * */
	public Map<HostCapacityEnum, Double> getHostDistribution();

	
	public int getCpuCapacityOfType(HostCapacityEnum hostType);
	
	public int getMemCapacityOfType(HostCapacityEnum hostType);
	
	public HostCapacity getHostCapacity(HostCapacityEnum hostType);
	
	public Host openNewHost(int tick);
	
	public void updateCurrentHostDemand(IDemandManager demandManager,Host host , List<VirtualMachine> vmsInHost, int tick);
	
	/**
	 * set the 3 list of HostManager.
	 */
	public void InitHostsInCloud();
	
	/**
	 * 
	 * @return list of all the open hosts and maybe candidate for closing as well.
	 */
	public List<Host> getOpenHosts();

	public int getNumberOfOpenHosts();

	public int getNumberOfClosedHosts();

	public int getNumberOfCandidatesForClosingHosts();
	
	public Host getHostByID(int hostIdentifier);

	public int getToatalCpuLoadOnCloud();

	public boolean openNewHostWithMinCpu(double delta,int tick);

	public void remAllCandidateForClosing();

	public void closeHostsWithCpuSumOf(int sumOfCpu);
	
	public void closeHost(Host host);
	
	public void makeHostCandidateForClosing(Host host,int tickRemainingForClosing);
	
	public void removeHostFromCandidateForClosing(Host host );
	
	public void setHostCurrentLoad(Host host,int cpuLoad, int memLoad);
	
	public void setHostCurrentCpuLoad(Host host,int cpuLoad) throws Exception;
	
	public void setHostCurrentMemLoad(Host host,int memLoad) throws Exception;
	
	public void updateHostCurrentLoad(Host host,int cpuLoad,int memLoad);
	
	public void updateHostCurrentCpuLoad(Host host,int cpuLoad) throws CpuLeakAtHostException;
	
	public void updateHostCurrentMemLoad(Host host,int memLoad) throws MemLeakAtHostException;
	
	public void setHostCurrentCpuDemand(Host host,int cpuLoad);
	
	public void removeListOfVmFromHosts(List<VirtualMachine> removeList);
	
	public void addVmToHost(Host host,VirtualMachine vm, int cpuLoad, int memLoad);
	
	public List<VirtualMachine> getVmsAtHost (Host host);
	
	public int getCpuAvailableAtHost(Host host);
	
	public int getTickHostTurnOn(Host host);

	public double getStartUpCostForHost(HostCapacityEnum hostCapacityEnum);

	public double getLoadCost(int size);

	public double getIncomeOnLoad(int totalCloudCPULoad);

	public int getToatalMemLoadOnCloud();
	
	public int getCPUReservation(Host host);

	public double getBaseCostForHost(HostCapacityEnum hostCapacityEnum);

	public void openHost(Host host, int tick);

	public Host getVm(VirtualMachine vm);

//	void addVmToHost(Host host, VirtualMachine vm);

	public void removeVmFromHost(Host host, VirtualMachine vm);

	public void relocateVm(VirtualMachine vm, Host fromHost, Host toHost, int cpu, int mem);

	public List<VirtualMachine> getAllVmAtOpenHosts();

	public void rejectVms(VirtualMachine vm);

}
